﻿using System;
using System.Diagnostics;

namespace SfsTools.Core
{
    /// <summary>
    /// Represents a file on a <see cref="FileSystem"/>.
    /// </summary>
    public interface IFile : IFileSystemObject
    {
        /// <summary>
        /// Gets the current size of the file in bytes.
        /// </summary>
        /// <value>The current size of the file in bytes, or <em>-1</em> if the file is deleted.</value>
        Int64 Length
        {
            get;
        }

        /// <summary>
        /// Opens the file in binary mode for reading.
        /// </summary>
        /// <returns>A <see cref="System.IO.Stream"/> that can be used to read from the file.</returns>
        /// <exception cref="InvalidOperationException">The file is deleted.</exception>
        System.IO.Stream OpenRead();

        /// <summary>
        /// Opens the file in binary mode for writing.
        /// </summary>
        /// <returns>A <see cref="System.IO.Stream"/> that can be used to write to the file.</returns>
        /// <exception cref="InvalidOperationException">The file is deleted.</exception>
        System.IO.Stream OpenWrite();

        /// <summary>
        /// Opens the file in binary mode for appending.
        /// </summary>
        /// <returns>A <see cref="System.IO.Stream"/> that can be used to write to the file.</returns>
        /// <exception cref="InvalidOperationException">The file is deleted.</exception>
        System.IO.Stream OpenAppend();

        /// <summary>
        /// Opens the file in binary mode.
        /// </summary>
        /// <param name="access">A <see cref="System.IO.FileAccess"/> value that specifies how the file can be accessed.</param>
        /// <returns>A <see cref="System.IO.Stream"/> that can be used to access the file.</returns>
        /// <exception cref="InvalidOperationException">The file is deleted.</exception>
        System.IO.Stream Open(System.IO.FileAccess access);

        /// <overloads>Opens the file in text mode for reading.</overloads>
        /// <summary>
        /// Opens the file in text mode for reading using the default encoding.
        /// </summary>
        /// <returns>A <see cref="System.IO.TextReader"/> that can be used to read from the file.</returns>
        /// <exception cref="InvalidOperationException">The file is deleted.</exception>
        System.IO.TextReader OpenText();

        /// <summary>
        /// Opens the file in text mode for reading using the specified encoding.
        /// </summary>
        /// <returns>A <see cref="System.IO.TextReader"/> that can be used to read from the file.</returns>
        /// <exception cref="InvalidOperationException">The file is deleted.</exception>
        System.IO.TextReader OpenText(System.Text.Encoding encoding);
    }
}
